
var city = "成都";
function loadXMLDoc() {
    var xmlhttp;
    if (window.XMLHttpRequest) {
        //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlhttp=new XMLHttpRequest();
    }
    else {
        // IE6, IE5 浏览器执行代码
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            var json = xmlhttp.responseText;
            json = JSON.parse(json);
            console.log(json);
            for(var i=0;i<json.daily_forecast.length;i++){
                var tq=document.querySelectorAll('.tq');
                var p=document.createElement('p');
                var span1=document.createElement('span');
                span1.innerHTML=json.daily_forecast[i].date;
                var span=document.createElement('span');
                span.innerHTML=json.daily_forecast[i].cond.txt_d;
                var span2=document.createElement('span');
                span2.innerHTML=json.daily_forecast[i].tmp.min+"~";
                var span3=document.createElement('span');
                span3.innerHTML=json.daily_forecast[i].tmp.max+"C";
                span2.classList.add('in');
                span3.classList.add('in');
                var list=document.querySelector('#list');
                list.appendChild(p);
                tq[i].innerHTML=span.innerHTML+(span2.innerHTML+span3.innerHTML);
                var fx=document.querySelectorAll('.fx-1');
                fx[i].innerHTML=json.daily_forecast[i].wind.dir;
                document.querySelector(".tq").innerHTML=json.daily_forecast[0]
                        .cond.txt_d+'&nbsp'+json.daily_forecast[0].tmp.min+"~"+json
                        .daily_forecast[0].tmp.max+"C";
            }
               document.querySelector(".cs").innerHTML = json.basic.city;
               document.querySelector(".cs-1").innerHTML = json.basic.city;
               document.querySelector(".cs-2").innerHTML = json.basic.city;
               document.querySelector(".cs-3").innerHTML = json.basic.city;
               document.querySelector(".cs-4").innerHTML = json.basic.city;
               document.querySelector(".cs-5").innerHTML = json.basic.city;
               document.querySelector(".cs-6").innerHTML = json.basic.city;
               document.querySelector(".drsg").innerHTML = json.suggestion.drsg.txt;
               document.querySelector("#xc").innerHTML = json.suggestion.cw.txt;
               document.querySelector("#ks").innerHTML = json.suggestion.air.txt;
               document.querySelector("#jk").innerHTML = json.suggestion.flu.txt;
               document.querySelector("#kq").innerHTML = json.suggestion.trav.txt;
               document.querySelector("#zwa").innerHTML = json.suggestion.uv.txt;
        }
    };
    xmlhttp.open("GET","https://bird.ioliu.cn/weather?city="+city,true);
    xmlhttp.send()
}
loadXMLDoc();

document.querySelector("#ibt").addEventListener('change',function () {
    city = this.value;
    loadXMLDoc()
});
